package cn.hdu.liang.core.service.product;

import cn.hdu.liang.core.bean.product.Brand;
import cn.hdu.liang.core.dao.product.BrandDao;
import cn.hdu.liang.core.query.product.BrandQuery;
import cn.itcast.common.page.Pagination;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class BrandServiceImpl implements BrandService {

    @Resource
    private BrandDao brandDao;

    @Override
    @Transactional(readOnly = true)
    public Pagination getBrandListWithPage(Brand brand) {
        //1:起始页 startRow = (pageNo - 1) * pageSize
        //2:每页数
        //3:总记录数
        Pagination pagination = new Pagination(brand.getPageNo(), brand.getPageSize(), brandDao.getBrandCount(brand));
        pagination.setList(brandDao.getBrandListWithPage(brand));
        return pagination;
    }

    @Override
    public List<Brand> getBrandList(BrandQuery brandQuery) {
        return brandDao.getBrandList(brandQuery);
    }

    @Override
    public void addBrand(Brand brand) {
        brandDao.addBrand(brand);
    }

    @Override
    public void deleteBrandByKey(Integer id) {
        brandDao.deleteBrandByKey(id);
    }

    @Override
    public void deleteBrandByKeys(Integer[] ids) {
        brandDao.deleteBrandByKeys(ids);
    }

    @Override
    public void updateBrandByKey(Brand brand) {
        brandDao.updateBrandByKey(brand);
    }

    @Override
    public Brand getBrandByKey(Integer id) {
        return brandDao.getBrandByKey(id);
    }
}
